package com.sqx.modules.course.controller.app;

import com.sqx.common.utils.Result;
import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.course.entity.CourseCollect;
import com.sqx.modules.course.service.CourseDetailsService;
import com.sqx.modules.course.service.CourseService;
import com.sqx.modules.sys.controller.AbstractController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Api(value = "APP短剧信息", tags = {"APP短剧信息"})
@RequestMapping(value = "/app/course")
public class AppCourseController extends AbstractController {
    @Autowired
    private CourseService courseService;
    @Autowired
    private CourseDetailsService courseDetailsService;

    @GetMapping("/selectCourse")
    @ApiOperation("查询短剧信息")
    public Result selectCourse(@ApiParam("页") Integer page, @ApiParam("条") Integer limit, @ApiParam("分类id") Long classifyId,
                               @ApiParam("搜索内容") String title,Long bannerId,Integer sort,String token, Integer isPrice,@ApiParam("1精选2热播3新剧") Integer selType) {
        return courseService.selectCourse(page, limit, classifyId, title,null,1,bannerId,sort,token,isPrice,selType);
    }


    @GetMapping("/selectCourseDetailsById")
    @ApiOperation("根据id查询短剧详情")
    public Result selectCourseDetailsById(Long id,String token){
        return courseDetailsService.selectCourseDetailsById(id,token);
    }

    @GetMapping("/selectCourseDetailsList")
    @ApiOperation("查询推荐视频")
    public Result selectCourseDetailsList(Integer page,Integer limit,String token){
        return courseDetailsService.selectCourseDetailsList(page, limit, token);
    }

    @Login
    @GetMapping("/selectCourseTitle")
    @ApiOperation("模糊根据短剧标题查询短剧")
    public Result selectCourseTitle(@ApiParam("页") Integer page, @ApiParam("条") Integer limit, @ApiParam("分类id") Long classifyId,
                               @ApiParam("搜索内容") String title,Long bannerId,Integer sort,String token, Integer isPrice,@ApiParam("1精选2热播3新剧") Integer selType) {
        return courseService.selectCourse(page, limit, classifyId, title,null,1,bannerId,sort,token,isPrice,selType);
    }

    @GetMapping("/selectCourseTitles")
    @ApiOperation("模糊根据短剧标题查询短剧")
    public Result selectCourseTitles(@ApiParam("页") Integer page, @ApiParam("条") Integer limit, @ApiParam("分类id") Long classifyId,
                                    @ApiParam("搜索内容") String title,Long bannerId,Integer sort,String token, Integer isPrice,@ApiParam("1精选2热播3新剧") Integer selType) {
        return courseService.selectCourse(page, limit, classifyId, title,null,1,bannerId,sort,token,isPrice,selType);
    }

    /**
     * 弃用
     * @param userId 用户id
     * @param page 页数
     * @param limit 条数
     * @param title 模糊搜索内容
     */
    @Login
    @GetMapping("/selectHomePage")
    @ApiOperation("查询首页推荐短剧")
    public Result selectHomePage(@RequestAttribute Long userId, @ApiParam("页数")Integer page ,@ApiParam("条")Integer limit,@ApiParam("模糊搜索内容")String title){
        return courseService.selectHomePage(userId,page,limit,title);
    }

    @Login
    @PostMapping("/deleteCourseDetailsById")
    @ApiOperation("删除在追的剧")
    public Result deleteCourseDetailsById(@ApiParam("剧集id") Long[] ids,@RequestAttribute Long userId){
        courseDetailsService.deleteCourseDetailsById(ids,userId);
        return Result.success().put("msg","删除成功");
    }

    /**
     * 查询是否追剧，查的应该是剧而不死剧集
     * @param courseId
     * @param userId
     * @return
     */
    @Login
    @GetMapping("/selIsCollect")
    @ApiOperation("查询是否追剧")
    public Result selIsCollect(@ApiParam("短剧id") Long courseId,@RequestAttribute("userId")Long userId){
        return courseService.selIsCollect(courseId,userId);
    }

    /**
     * 查询退卷免费且是推荐的剧集
     * @param userId 用户id
     * @param page 页数
     * @param limit 条数
     * @return 返回剧集列表
     */
    @Login
    @GetMapping("/selectRecommendCourseDetailsList")
    public Result selectRecommendCourseDetailsList(@RequestAttribute("userId")Long userId,Integer page,Integer limit){
        return courseService.selectRecommendCourseDetailsList(userId,page,limit);
    }

    /**
     * 根据用户id查询用户是否追剧
     * @param userId
     * @param courseId
     * @param classify 传什么类型，什么类型就是判断追剧的依据 1点赞2收藏3追剧
     * @return bool
     */
    @Login
    @GetMapping("/selCourseByCourseCollect")
    public Result selCourseByCourseCollect(@RequestAttribute("userId")Long userId,Integer courseId,int classify){
        return courseService.selCourseByCourseCollect(userId,courseId,classify);
    }

    /**
     * 按分类返回短剧信息
     * @param
     * @param page
     * @param limit
     * @param title
     * @return
     */
    @GetMapping("/selectHomePageCourse")
    public Result selectHomePageCourse(@ApiParam("页数")Integer page ,@ApiParam("条")Integer limit,@ApiParam("模糊搜索内容")String title,String userId){
        return courseService.selectHomePageCourse(page,limit,title,userId);
    }

    /**
     * 追剧/取消追剧
     * @param userId
     * @param courseId
     * @return
     */
    @Login
    @PostMapping("/addCoursePursue/{courseId}")
    public Result addCoursePursue(@RequestAttribute("userId")Long userId,@PathVariable Integer courseId){
        return courseService.addCoursePursue(userId,courseId);
    }

    /**
     * 查询用户追剧列表
     * @param userId
     * @param page
     * @param limit
     * @return
     */
    @Login
    @GetMapping("/coursePursueByUserId")
    public Result coursePursueByUserId(@RequestAttribute("userId")Long userId,Integer page,Integer limit){
        return courseService.coursePursueByUserId(userId,page,limit);
    }

    /**
     * 修改数据库视频链接
     * @return
     */
    @PostMapping("/uploadVideo")
    public Result courseService(){
        return courseService.courseService();
    }
}
